home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / pubfictn.lha / pubfiction.c < prev    next >
C/C++ Source or Header  |  1995-11-10  |  6KB  |  180 lines

  1. /*    Name:    pubfiction.c
  2.     Descr:    Open/close a public screen with selectable resolution, clone pens from workbench.
  3.     Date:    10-Nov-1995
  4.     Author:    Henrik Wetterström a.k.a. Procyon
  5.     Email:    hwefri92@tufvan.hv.se
  6.     Smail:    Who cares?
  7.     Other:    Works fine on my 68EC030 and MicroVitec multiscan monitor (in lots of resolutions)
  8.         but since I have little experience in C programming on the Amiga (I usually code
  9.         C in Unix or assembler on the Amiga) could I have missed some detail. Feel free
  10.         to finger point them to me if you find them...
  11.         The background to this little utility is that one guy (forgot the name) asked
  12.         about such utility on IRC #amiga and I pointed to a PAL/NTSC only version
  13.         called PSX. Later I figured out that it should be easy to make one, and it
  14.         actually was easy... :)
  15.     Copyright:
  16.         If you are able to earn some money from this material then go ahead and do so, BUT
  17.         you must tell me HOW you did it. However, I would find it extremely cool to find a
  18.         greeting to me in a product that gained from this material, so please greet me if
  19.         you use it.
  20.     Disclaimer:
  21.         I can not assure one thing about this product, it could trash your computer,
  22.         infect you with syphilis, make you sister pregnant, help you to win the lottery,
  23.         explode your monitor. No matter what it does to you, it is all your fault and
  24.         responsibility. If you are the sensitive or lawyer kind of person do I suggest
  25.         that you make you own program instead of using this.
  26.     Greetings:
  27.         My old fellas in Digital Technology, my drinking brothers in Brothers in Beer,
  28.         the dudes on #amiga, all babes worldwide, all breweries worldwide, all the
  29.         folks here at Växjö University, Honko del Oro.
  30.     Whishes:
  31.         Peace and freedom for everyone, SparcCenter 2000e, SGI Onyx, BeBox,
  32.         free sex & beer, etc...
  33.     Comment:
  34.         The name (PubFiction) is a smartass name from the great movie "Pulp fiction"
  35.         which I still have not seen, but it looks like I am the only person on this
  36.         planet who have not seen it so I guess I will see it alone...
  37.         If this program had a scroller would this text been there... :)
  38. */
  39.  
  40. #define INTUI_V36_NAMES_ONLY
  41.  
  42. #include <string.h>
  43. #include <ctype.h>
  44.  
  45. #include <exec/types.h>
  46. #include <intuition/intuition.h>
  47. #include <intuition/screens.h>
  48. #include <dos/rdargs.h>
  49.  
  50. #include <clib/exec_protos.h>
  51. #include <clib/dos_protos.h>
  52. #include <clib/intuition_protos.h>
  53.  
  54. struct Library *IntuitionBase;
  55.  
  56. ULONG mode=0L;
  57.  
  58. struct Screen *getpubscreen( ULONG modeid, long depth, char *name, int shanghai, int popup ) {
  59.     struct Screen *wbscreen,*myscreen=NULL;
  60.     struct TagItem screentags[5];
  61.     struct DrawInfo *screen_drawinfo;
  62.     static UBYTE *wbname  = "Workbench";
  63.     UWORD pm=0;
  64.  
  65.     if( wbscreen=LockPubScreen(wbname) ) {
  66.         if ( screen_drawinfo=GetScreenDrawInfo(wbscreen) )
  67.             {
  68.             screentags[0].ti_Tag  = SA_Pens;
  69.             screentags[0].ti_Data = (ULONG)(screen_drawinfo->dri_Pens);
  70.             screentags[1].ti_Tag  = SA_DisplayID;
  71.             screentags[1].ti_Data = modeid;
  72.             screentags[2].ti_Tag  = SA_Depth;
  73.             screentags[2].ti_Data = (ULONG)depth;
  74.             screentags[3].ti_Tag  = SA_PubName;
  75.             screentags[3].ti_Data = (ULONG)name;
  76.             screentags[4].ti_Tag  = TAG_END;
  77.             screentags[4].ti_Data = NULL;
  78.  
  79.             FreeScreenDrawInfo(wbscreen,screen_drawinfo);
  80.         }
  81.         else {
  82.             screentags[0].ti_Tag  = SA_DisplayID;
  83.             screentags[0].ti_Data = modeid;
  84.             screentags[1].ti_Tag  = SA_PubName;
  85.             screentags[1].ti_Data = (ULONG)name;
  86.             screentags[2].ti_Tag  = SA_Depth;
  87.             screentags[2].ti_Data = depth;
  88.             screentags[3].ti_Tag  = TAG_END;
  89.             screentags[3].ti_Data = NULL;
  90.         }
  91.  
  92.         if( myscreen=OpenScreenTagList(NULL, screentags) ) {
  93.             PubScreenStatus(myscreen,0);
  94.             if(shanghai) pm=SHANGHAI;
  95.             if(popup) pm=pm|POPPUBSCREEN;
  96.             SetDefaultPubScreen(name);
  97.             SetPubScreenModes(pm);
  98.         }
  99.  
  100.         UnlockPubScreen(wbname,wbscreen);
  101.     }
  102.     return myscreen;
  103. }
  104.  
  105. int modelong( char *s ) {
  106.     int i,b,l=strlen(s);
  107.     if( (l>2) && (l<10) && (s[0]=='0') && (s[1]=='x' ) ) {
  108.         for(i=2;i<l;i++) {
  109.             mode=mode<<4;
  110.             b=0xff & toupper(s[i]);
  111.             switch(b) {
  112.             case '0':case '1':case '2':case '3':case '4':
  113.             case '5':case '6':case '7':case '8':case '9':
  114.                 b=0xf & (b-'0');
  115.                 mode=mode|b;
  116.                 break;
  117.             case 'A':case 'B':case 'C':
  118.             case 'D':case 'E':case 'F':
  119.                 b=0xf & (b-'A'+10);
  120.                 mode=mode|b;
  121.                 break;
  122.             default:
  123.                 return FALSE;
  124.             }
  125.         }
  126.         return TRUE;
  127.     }
  128.     return FALSE;
  129. }
  130.  
  131. int closepubscreen(char *name) {
  132.     struct Screen *scr;
  133.     int r=FALSE;
  134.     if(scr=LockPubScreen(name)) {
  135.         UnlockPubScreen(name,scr);
  136.         r=CloseScreen(scr);
  137.     }
  138.     return r;
  139. }
  140.  
  141. int main(int argc, char **argv) {
  142.     char template[]="OPEN/S,CLOSE/S,PUBNAME/K,MODEID/K,DEPTH/N,SHANGHAI/S,POPUP/S";
  143.     LONG args[]={0,0,0,0,0,0,0};
  144.     struct RDArgs *argp;
  145.     static char defname[]="Procyon";
  146.     char *pnam=defname;
  147.     long dep=3;
  148.  
  149.     if( argp=ReadArgs(template,args,NULL) ) {
  150.         if( args[0]==FALSE && args[1]==FALSE ) {
  151.             VPrintf("Open or close operation not specified.\n",NULL);
  152.             FreeArgs(argp);
  153.             return 10;
  154.         }
  155.         if(args[2]) pnam=(char *)args[2];
  156.         if(args[3]) { 
  157.             if( (modelong((char *)args[3]))==FALSE ) {
  158.                 VPrintf("Invalid modeid.\n",NULL);
  159.                 FreeArgs(argp);
  160.                 return 10;
  161.             }
  162.         }
  163.         else mode=0x99004;
  164.         if(args[4]) dep=*(long *)args[4];
  165.         if ( IntuitionBase= OpenLibrary("intuition.library",37L) ) {
  166.             if( args[0] ) {
  167.                 if( getpubscreen(mode,dep,pnam,(int)args[5] ,(int)args[6] )==NULL )
  168.                     VPrintf("Failed to open screen.\n",NULL);
  169.             }
  170.             if( args[1] ) {
  171.                 if( args[2]==NULL ) VPrintf("No screen name was passed.\n",NULL);
  172.                 else if( closepubscreen((char *)args[2])==FALSE)
  173.                     VPrintf("Failed to close screen '%s'.\n",&args[2]);
  174.             }
  175.             CloseLibrary(IntuitionBase);
  176.         }
  177.         FreeArgs(argp);
  178.     }
  179. }
  180.